package org.example.leetcpde;

import org.example.INode;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Node;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

public class removeNthFromEnd implements IListNode {

    @Test
    void removeNthFromEnd() {
        ListNode fill = new ListNode().fill("[1,2]");
        ListNode node = removeNthFromEnd(fill, 1);
        System.out.println(22);
    }

    public ListNode removeNthFromEnd(ListNode head,
                                     int n) {
        ListNode root = new ListNode(0, head), tail = root;

        for (int i = 0; i < n; i++) {
            head = head.next;
        }

        while (head != null) {
            tail = tail.next;
            head = head.next;
        }

        tail.next = tail.next.next;
        return root.next;
    }
}
